package com.youdianstar.app.entity

import com.google.gson.annotations.SerializedName

/**
 * File: BranchDetailInfo
 * Description: 网点详情 - 详情接口返回的数据结构
 */
data class BranchDetailInfo(
    @SerializedName("id")
    val id: Int,
    
    @SerializedName("name")
    val name: String,
    
    @SerializedName("address")
    val address: String,
    
    @SerializedName("open_time")
    val openTime: String,
    
    @SerializedName("map_latitude")
    val latitude: Double,
    
    @SerializedName("map_longitude")
    val longitude: Double,
    
    @SerializedName("logo")
    val logo: String,
    
    @SerializedName("background")
    val background: String?,
    
    @SerializedName("tel")
    val tel: String?,
    
    @SerializedName("mobile")
    val mobile: String?,
    
    @SerializedName("graphInfo")
    val graphInfo: GraphInfo?,
    
    @SerializedName("distance")
    val distance: Double? = null
) {
    // 转换为BranchInfo
    fun toBranchInfo(): BranchInfo {
        val isOpen = graphInfo?.open ?: false
        
        // 优先使用mobile，如果没有则使用tel
        val phoneNumber = if (!mobile.isNullOrEmpty()) mobile else tel
        
        return BranchInfo(
            id = id,
            branchName = name,
            address = address,
            addressMap = null,
            distance = distance ?: 0.0,
            lat = latitude,
            lng = longitude,
            logo = logo,
            images = background,
            website = null,
            landlinePhone = phoneNumber,
            rent = graphInfo?.depotBorrow ?: 0,
            recovery = graphInfo?.depotEmpty ?: 0,
            isBusiness = isOpen,
            openTime = openTime,
            billing = null
        )
    }
}

/**
 * 网点状态信息
 */
data class GraphInfo(
    @SerializedName("open")
    val open: Boolean,
    
    @SerializedName("depotBorrow")
    val depotBorrow: Int,
    
    @SerializedName("depotEmpty")
    val depotEmpty: Int,
    
    @SerializedName("depotCount")
    val depotCount: Int,
    
    @SerializedName("depotCharge")
    val depotCharge: Int,
    
    @SerializedName("deoptFailure")
    val depotFailure: Int,
    
    @SerializedName("borrow")
    val borrow: Boolean,
    
    @SerializedName("empty")
    val empty: Boolean
)

